<?php

namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class OrderDetailController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    //加载明细表主页
    public function index()
    {  
        //添加搜索功能
        $db=DB::table('orderdetail');
       //判断并封装搜索条件
       $params = array();
       if(!empty($_GET['name'])){
           $db->where("bid","like","%{$_GET['name']}%");
           $params['name'] = $_GET['name']; //维持搜索条件
       }
       //获取状态为1的数据
        $list=$db->where('status','=',"1")
                 ->paginate(5);

        return view('admin.order.indexdetail',['list'=>$list,
                                                'params'=>$params  
                                                            ]);
        
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    //回收站获取数据
    public function create()
    {   

         //添加搜索功能
        $db=DB::table('orderdetail');
       //判断并封装搜索条件
       $params = array();
       if(!empty($_GET['name'])){
           $db->where("bid","like","%{$_GET['name']}%");
           $params['name'] = $_GET['name']; //维持搜索条件
       }
       //获取状态为1的数据
        $list=$db->where('status','=',"0")
                 ->paginate(5);

        return view('admin.order.recyledetail',['list'=>$list,
                                                'params'=>$params  
                                                            ]);
        
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        //
    }
    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $db=DB::table('orderdetail');
      
        $m=DB::table('orderdetail')
            ->where('id', $id)
            ->update(['status' => 0]);
        $list=$db->where('status','=','0')->paginate(5);
        
        if($m>0){
            return view('admin.order.recyledetail',['list'=>$list]);   
        }else{
            return back()->with('err','请重新放入回收站！');
        }                               
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    //设置回收站还原操作
    public function edit($id)
    {
        $db=DB::table('orderdetail');
       //判断并封装搜索条件
       $params = array();
       if(!empty($_GET['name'])){
           $db->where("bid","like","%{$_GET['name']}%");
           $params['name'] = $_GET['name']; //维持搜索条件
       }
       //获取状态为1的数据
       $m=DB::table('orderdetail')
            ->where('id', $id)
            ->update(['status' => 1]);

        $list=$db->where('status','=',"1")
                 ->paginate(5);

        //判断
         if($m>0){
            return view('admin.order.indexdetail',['list'=>$list,
                                                'params'=>$params  
                                                            ]);    
         }else{
            return back()->with('err',"还原失败请重新操作！");
         }        
           
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $m=DB::table('orderdetail')->where('id',"$id")->delete();
        if($m>0){
            return back()->with('err','删除成功！');
        }else{
            return back()->with('err',"是删除失败,请重操作！");
        }
        
        
    }
   
}
